﻿using System;
using System.Collections.Generic;

using System.Text;
using RebEngine.Interfaces;
using Microsoft.Xna.Framework.Audio;
using RebEngine.Managers;

namespace RebEngine.Sound
{
    public class RebSound : IRebSound
    {
        private string sFileName;
        public string FileName
        {
            get { return sFileName; }
            set { sFileName = value; }
        }

        private SoundEffect sBaseSound;
        public SoundEffect BaseSound
        {
            get { return sBaseSound; }
        }

        private SoundEffectInstance sInstance;
        public SoundEffectInstance SoundInstance
        {
            get { return sInstance; }
            set { sInstance = value; }
        }

        private bool _readyToPlay = false;
        public bool ReadyToPlay
        {
            get { return _readyToPlay; }
        }

        public RebSound()
        { }

        public RebSound(string filename)
        {
            sFileName = filename;
        }

        public void LoadContent()
        {
            if (!String.IsNullOrEmpty(sFileName))
            {
                try
                {
                    sBaseSound = EngineManager.ContentManager.Load<SoundEffect>("Content/Sound/"+ sFileName);
                    _readyToPlay = true;
                }
                catch
                {
                    sBaseSound = EngineManager.ContentManager.Load<SoundEffect>("Content/Sound/NoSound");
                    _readyToPlay = true;
                }
            }
        }

        public void UnloadContent()
        {
            sBaseSound.Dispose();
        }

    }
}
